home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 008 / src / _main.c next >
C/C++ Source or Header  |  1995-03-17  |  2KB  |  121 lines

  1. #include "lattice/stdio.h"
  2. #include "lattice/ctype.h"
  3. #include "lattice/ios1.h"
  4.  
  5. #include "workbench/startup.h"
  6. #include "libraries/dos.h"
  7.  
  8. #define MAXARG 32              /* maximum command line arguments */
  9.  
  10. #ifndef TINY
  11. extern int _stack,_fmode,_iomode;
  12. #endif
  13. extern int LoadAddress;
  14.  
  15. extern struct UFB _ufbs[];
  16. int argc;            /* arg count */
  17. char *argv[MAXARG];        /* arg pointers */
  18.  
  19. #define MAXWINDOW 40
  20. extern struct WBStartup *WBenchMsg;
  21. static char window[MAXWINDOW] = "con:10/10/320/80/";
  22.  
  23. /**
  24. *
  25. * name         _main - process command line, open files, and call "main"
  26. *
  27. * synopsis     _main(line);
  28. *              char *line;     ptr to command line that caused execution
  29. *
  30. * description    This function performs the standard pre-processing for
  31. *        the main module of a C program.  It accepts a command
  32. *        line of the form
  33. *
  34. *            pgmname arg1 arg2 ...
  35. *
  36. *        and builds a list of pointers to each argument.  The first
  37. *        pointer is to the program name.  For some environments, the
  38. *        standard I/O files are also opened, using file names that
  39. *        were set up by the OS interface module XCMAIN.
  40. *
  41. **/
  42. _main(line)
  43. char *line;
  44. {
  45. char c;
  46. int x;
  47.  
  48. /*
  49. *
  50. * Build argument pointer list
  51. *
  52. */
  53. for(argc = 0; argc < MAXARG; )
  54.     {
  55.     while(isspace(*line)) line++;
  56.     if(*line == '\0') break;
  57.     argv[argc++] = line;
  58.     while((*line != '\0') && (isspace(*line) == 0)) line++;
  59.     c = *line;
  60.     *line++ = '\0';
  61.     if(c == '\0') break;
  62.     }
  63. /*
  64. *
  65. * Open standard files
  66. *
  67. */
  68. #ifndef TINY
  69. #ifdef GIMME_A_BUG
  70. stdin->_file = 0;
  71. stdin->_flag = _IOREAD;
  72. stdout->_file = 1;
  73. stdout->_flag = _IOWRT;
  74. stderr->_file = 2;
  75. stderr->_flag = _IOWRT;
  76.  
  77. if (argc == 0)        /* running under workbench    */
  78.     {
  79.     strncat(window, WBenchMsg->sm_ArgList->wa_Name,MAXWINDOW);
  80.     _ufbs[0].ufbfh = Open(window,MODE_NEWFILE);
  81.     _ufbs[1].ufbfh = _ufbs[0].ufbfh;
  82.     _ufbs[1].ufbflg = UFB_NC;
  83.     _ufbs[2].ufbfh = _ufbs[0].ufbfh;
  84.     _ufbs[2].ufbflg = UFB_NC;
  85.     x = 0;
  86.     }
  87. else            /* running under CLI        */
  88. #endif
  89. #endif GIMME_A_BUG
  90. #ifdef GIMME_A_BUG
  91.     {
  92.     _ufbs[0].ufbfh = Input();
  93.     _ufbs[1].ufbfh = Output();
  94.     _ufbs[2].ufbfh = Open("*", MODE_OLDFILE);
  95.     x = UFB_NC;            /* do not close CLI defaults    */
  96.     }
  97. #endif GIMME_A_BUG
  98.  
  99. _ufbs[0].ufbflg |= UFB_OP | UFB_RA | UFB_NC;
  100. _ufbs[1].ufbflg |= UFB_OP | UFB_WA | UFB_NC;
  101. _ufbs[2].ufbflg |= UFB_OP | UFB_WA | UFB_NC;
  102.  
  103. /*
  104. *
  105. * Call user's main program
  106. *
  107. */
  108. #ifdef DEBUG
  109. printf("load address = %lx\n",LoadAddress);
  110. Debug(0);
  111. #endif
  112.  
  113. main(argc,argv);              /* call main function */
  114. #ifndef TINY
  115. exit(0);
  116. #else
  117. _exit(0);
  118. #endif
  119. }
  120.  
  121.